<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="edge" />
<link rel="shortcut icon" href="static/style/images/favicon.ico" />
<!-- [EasyUI] -->
<link id="easyuiTheme" rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.5.1/themes/gray/easyui.css" />
<link id="easyuiTheme" rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.5.1/themes/icon.css" />
<script type="text/javascript" src="/static/js/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="/static/jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/static/jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="/static/js/HhUtil.js?t=20170109"></script>
<!-- [扩展样式] -->
<link rel="stylesheet" type="text/css" href="/static/css/dreamlu.css" />
<link rel="stylesheet" type="text/css" href="/static/css/icommon.css" />
<link rel="stylesheet" type="text/css" href="/static/css/login.css" />
<!--<script type="text/javascript" src="static/js/login.js" charset="utf-8"></script>-->
<title>用户管理</title>
<script type="text/javascript">

    var dataGrid;
    var flag = 1;

    $(function () {
        //用户维护（新增、修改）界面
        $("#addDialog").dialog({
            title: "新增",
            width: '60%',
            height: '70%',
            closed: true,
            cache: false,
            modal: true,
            buttons: [{
                text: '保存',
                handler: function () {
                    saveUser();
                }
            }, {
                text: '关闭',
                handler: function () {

                    $("#addDialog").dialog("close");
                }
            }]
        });

        //首次进入拉取
        dataGrid = $('#dataGrid').datagrid({
            url: '/getdriverschool',
            method:'get',
            fit: true,
            striped: true,
            rownumbers: true,
            singleSelect: true,
            idField: 'phone',
            pagination: true,
            pageSize: 20,
            pageList: [10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
            columns: [[{
                width: '20%',
                title: ' id',
                field: 'id',
                hidden: true
            }, {
                width: '40%',
                title: ' 地市',
                field: 'area'
            },{
                width: '50%',
                title: ' 驾校',
                field: 'school'
            },{
                field: 'action',
                title: '操作',
                width: '10%',
                formatter: function (value, row, index) {
                    var str = '';
                    str += $.formatString('<a href="javascript:void(0)" class="user-easyui-linkbutton-del" data-options="plain:true,iconCls:\'icon-del\'" onclick="deleteFun(\'{0}\');" >删除</a>', row.id);
                    return str;
                }}
            ]],
            onLoadSuccess: function (data) {
                $('.user-easyui-linkbutton-del').linkbutton({text: '删除', plain: true, iconCls: 'icon-del'});
            },
            toolbar: '#toolbar'
        });
        });

        function searchFun() {
            dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
        }

        //新增用户
        function addFun() {
            $("#addForm").form("clear");
            $("#addDialog").dialog("open");
        }

        //保存
        function saveUser() {
            $("#addForm").form("submit", {
                url: "/setdriverschool",
                onSumbit: function () {
                    $("#addForm").form.validate();
                },
                success: function (data) {
                    data = JSON.parse(data);
                    if (data.code == "0") {
                        $("#addDialog").dialog("close");
                        HdUtil.messager.slide(data.msg);
                        $("#dataGrid").datagrid("reload");
                    } else {
                        $("#addDialog").dialog("close");
                        HdUtil.messager.error(data.msg);
                    }
                }
            });
        }

        //删除
        function deleteFun(id) {
            $.messager.confirm(HdUtil.constant.CONFIRM, HdUtil.constant.DELETE_CONFIRM, function (r) {
                    if (r) {
                        $.ajax({
                            method: "post",
                            url: "/deldriverschool",
                            data: {
                                id: id
                            },
                            success: function (data) {
                                if (data.code == "0") {
                                    HdUtil.messager.slide(HdUtil.constant.DELETE_SUCCESS);
                                    $("#dataGrid").datagrid("reload");
                                } else {
                                    HdUtil.messager.error(data.msg);
                                }
                            }
                        })
                    }
                });

        }



    </script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
<div data-options="region:'north',border:false" style="height: 30px; overflow: hidden;background-color: #fff">
  <form id="searchForm">
    <table>
      <tr>
          <th>搜索地市:</th>
          <td><input name="area" placeholder="搜索地市"/></td>

          <th>搜索驾校:</th>
          <td><input name="school" placeholder="搜索驾校"/></td>
        <td>
          <a href="javascript:void(0);" class="easyui-linkbutton"
                       data-options="iconCls:'icon-search',plain:true" onclick="searchFun();">查询</a> </td>
          <td>
          <a onclick="addFun();" href="javascript:void(0);" class="easyui-linkbutton"
           data-options="plain:true,iconCls:'icon-add'">添加</a></td>
      </tr>
    </table>
  </form>

</div>
<div data-options="region:'center',border:true,title:'信息列表'">
  <table id="dataGrid" data-options="fit:true,border:false">
  </table>
</div>


<div id="addDialog">
    <form id="addForm" method="post">
        <table>
            <br/>
            <tr>
                <td style="vertical-align: middle">地市：</td>
                <td>
                    <input name="area" class="easyui-textbox" data-options="required:true"/>
                </td>
                <td style="vertical-align: middle">驾校：</td>
                <td>
                    <input name="school" class="easyui-textbox" data-options="required:true"/>
                </td>
            </tr>
        </table>
    </form>
</div>

</body>
</html>
